import json

from Config.cfg import cfg
from Config.cfg.cfgurl import cfg_person_url
from Config.cfg.cfgpar import cfg_person_parameter
from Lib.Base.base_request import request
from Lib.Base.token_api import get_token


class ApiPerson():

    def __init__(self):
        self.method = f'{cfg.api_post}'
        self.url_add = f'{cfg_person_url.person_api_add}'
        self.url_del = f'{cfg_person_url.person_api_delete}'
        self.url_dels = f'{cfg_person_url.person_api_deletes}'
        self.url_get_code = f'{cfg_person_url.person_api_get}'
        self.header = get_token()

    def person_add(self, json_params_add):
        return request.run_main(self.method, self.url_add, json_params_add, self.header)

    def person_delete(self, json_params_del):
        return request.run_main(self.method, self.url_del, json_params_del, self.header)

    def person_deletes(self, json_params_dels):
        return request.run_main(self.method, self.url_dels, json_params_dels, self.header)

    def person_code_get(self, json_params_get_code):
        return request.run_main(self.method, self.url_get_code, json_params_get_code, self.header)


apiperson = ApiPerson()
if __name__ == "__main__":
    # json_params = json.loads(f'{cfg_person_parameter.personAdd001}')
    # res = apiperson.person_add(json_params)
    # print(res)
    # json_params = json.loads(f'{cfg_person_parameter.personDels}')
    param_code_get003 = {
        "codes": [f'{cfg_person_parameter.personCodeGet001}', f'{cfg_person_parameter.personCodeGet002}']}
    res = apiperson.person_deletes(param_code_get003)
    # json_params = json.loads(f'{cfg_person_parameter.personCodeGet002}')
    # res = apiperson.person_code_get(json_params)
    # print(res)
